<?php
	class Link{
		protected $re;
		protected function f1(){
			$link=mysqli_connect('localhost','root','root','student') or die('链接失败');
			$sql="select * from info";
			$r=mysqli_query($link, $sql);
			$re=mysqli_fetch_all($r,MYSQLI_ASSOC);
			$this->re=$re;
		}
	}
	
	class Show extends Link{
		public function __construct(){
			$this->f1();
			echo '<table border="1">';
			echo '<tr><td>列名</td><td>姓名</td><td>年龄</td><td>班级</td></tr>';
			foreach($this->re as $v){
				echo '<tr>';
				echo '<td>'.$v['id'].'</td>';
				echo '<td>'.$v['name'].'</td>';
				echo '<td>'.$v['year'].'</td>';
				echo '<td>'.$v['class'].'</td>';
				echo '</tr>';
			}
			echo '</table>';
		}
	}
	
//	$link1=new Link();
	$show1=new Show;
//	echo '<pre>';
//	var_dump($link1);
//	var_dump($show1);
?>